package com.NeuglsWorkStudio.UI.FormElement.Component
{
	import com.NeuglsWorkStudio.Colors.HSL;
	import com.NeuglsWorkStudio.UI.FormElement.Config.TConfig;
	import com.NeuglsWorkStudio.UI.FormElement.Config.TProgressBarConfig;
	
	import flash.display.Sprite;
	
	public class TProgressBar extends TComponent
	{
		private var _FProgressBar:Sprite;
		private var _FMax:int;
		private var _FMin:int;
		private var _FPosition:int;
		private var _FBaseColor:int;
		
		public function TProgressBar(AConfig:TConfig)
		{
			super(AConfig);
		}
		
		public function get Position():int
		{
			return _FPosition;
		}

		public function set Position(value:int):void
		{
			_FPosition = value;
			Paint();
		}

		public function get Min():int
		{
			return _FMin;
		}

		public function set Min(value:int):void
		{
			_FMin = value;
			Paint();
		}

		public function get Max():int
		{
			return _FMax;
			
		}

		public function set Max(value:int):void
		{
			_FMax = value;
			Paint();
		}

		override protected function Init():void{
			super.Init();
			
			_FProgressBar=new Sprite();
			_FMax=(_FConfig as TProgressBarConfig).Max;
			_FMin=(_FConfig as TProgressBarConfig).Min;
			_FPosition=(_FConfig as TProgressBarConfig).Position;
			_FBaseColor=(_FConfig as TProgressBarConfig).BaseColor;
			this.addChild(_FProgressBar);
			
			Paint();
		}
		
		protected function Paint():void{
			var RoundRadius:Number=5;
			var borderSize:Number=1;
			var barWidth:Number=(_FPosition*_FConfig.Width)/(_FMax-_FMin);
			var barHeight:Number=_FConfig.Height-borderSize;
			with(_FProgressBar.graphics){
				clear();
				lineStyle(1,HSL.AddLightToColor(_FBaseColor,0.15));
				beginFill(0,0);
				//drawRoundRect(0,0,_FConfig.Width,_FConfig.Height,RoundRadius*2,RoundRadius*2);
				drawRect(0,0,_FConfig.Width,_FConfig.Height);
				endFill();
				lineStyle(null,0,0);
				beginFill(HSL.AddLightToColor(_FBaseColor,-0.05),0.7);
				//drawRoundRect(borderSize,borderSize,barWidth,barHeight,RoundRadius*2,RoundRadius*2);
				drawRect(borderSize,borderSize,barWidth,barHeight);
				endFill();
			}
		}
	}
}